package Tools;

import java.util.ArrayList;


import android.graphics.Canvas;
import android.graphics.Paint;

public class GameButtonManage {
	
	private ArrayList<GameButton>  gameButtonArrayList ;
	public static GameButtonManage instaceGameButtonManage;
	
	public static GameButtonManage getInstance()
	{
		if(instaceGameButtonManage == null)
			instaceGameButtonManage = new GameButtonManage();
		return instaceGameButtonManage;
	}
	public GameButtonManage() {
		gameButtonArrayList = new ArrayList<GameButton>();
	}
	
	public void addGameButton(GameButton gameButton)
	{
		gameButtonArrayList.add(gameButton);
	}
	
	public GameButton getGameButton(int arrayListButtonID)
	{
		if(gameButtonArrayList.size() >= 1)
				return gameButtonArrayList.get(arrayListButtonID);
		return null;
	}
	
	
	public void deleteGameButton(int arrayListButtonID)
	{
			gameButtonArrayList.remove(arrayListButtonID);
	}
	
	public void deleteGameButton(GameButton gameButton)
	{
		if(gameButtonArrayList.size()>0)
			gameButtonArrayList.remove(gameButton);
	}
	
	public void clearAllGameButton()
	{
		gameButtonArrayList.clear();
	}
	
	public int getTotalButtonAmout()
	{
		return gameButtonArrayList.size();
	}
	
	public void clearEffect() //清楚伸展效果
	{
		for (int i = 0; i < gameButtonArrayList.size(); i++) {
			gameButtonArrayList.get(i).clearStrectchEffect();
		}
	}
	
	public void OnButtonDraw(Canvas canvas,Paint paint)
	{
		for (int i = 0; i < gameButtonArrayList.size(); i++) {
			gameButtonArrayList.get(i).onDraw(canvas,paint);
		}
	}
	
	public int onButtonPressed(float touchX,float touchY)
	{
		for (int i = 0; i < gameButtonArrayList.size(); i++) {
				if(!gameButtonArrayList.get(i).isCanTouched())
					continue;
				if(gameButtonArrayList.get(i).listener != null)
				{
					if(gameButtonArrayList.get(i).OnButtonPressed(touchX, touchY))
						return i;
				}
		}
		return -1;
	}
}
